home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Alles Voor Internet / Tout Pour Internet
/
alles voor internet.iso
/
MacInternet™
/
Modem
/
QuickDial_1.3 Folder
/
quickdial.p 1⁄21⁄94 (1.3)
< prev
next >
Wrap
Text File
|
1994-01-22
|
6KB
|
239 lines
program quickDial;
{ QuickDial takes text and dumps AT^m ATD<text>,;H to the modem. This dials the number & hangs up after 2 second. }
{ The program first gets text from STR id 128. This is the dialing prefix prepended to all numbers. }
{ Then it tries to read STR id 129. If that is blank, it tries to read the clipboard for the number. }
{ This way, you can have a general quickdial for all your numbers and special ones to call specific }
{ frequently-used (your mother, for example). }
{ The program will beep if there is no text in STR 129 or the clipboard. }
{ The program is basically meant to go under the System 7 Apple menu. }
{ Unlike the few programs I looked at, I am nice & properly close the serial port when done! }
{ I found the source code of the Busy or Not DA by Kiron Bondale, 1988, quite useful. }
{ Feel free to send email to mblain@aol.com with comments/suggestions/etc... }
{ Matthew Blain, 7/30/93. Public Domain. This source code can be freely distributed. }
{ Version 1.0.1 of 8/1/93 should close the serial port. V 1.0 didn't really. }
{ VErsion 1.0.2 of 8/6 does atdT (tone dial) and also sends a prelimiary AT^m }
{ Version 1.1 of 8/26/93 reads STR's id 128 and 129. If it is blank, it reads the clipboard. }
{ Version 1.2 of 8/27/93 waits for a response from the modem before quitting . I assume Q0. }
{ Version 1.3 of 1/21/94 doesn't wait for a response. Rather, it reads STR id 130, and waits }
{ that many seconds before quitting. }
{ Version 1.3 also no longer assumes the ATDT commands; you must store ATD in str 128 if you want that. }
{ It still appends ;H0, however. }
uses
Serial, Scrap;
var
InRefNum, OutRefNum, i: integer;
waiter: longint;
Err: OSErr;
numb, s: str255;
procedure init;
begin
{ This is the ultimate in facelessness... }
{ Don't even bother initializing everything }
{ InitGraf(@ThePort); InitFonts; InitWindows; InitMenus; TEInit; InitDialogs(nil);}
{ FlushEvents(EveryEvent, 0);}
end;
procedure openserial;
var
config: integer;
begin
config := baud1200 + data8 + stop10 + NoParity;
{ Baud1200 should work with any modem! }
Err := OpenDriver('.AIn', inRefNum);
Err := OpenDriver('.AOut', OutRefNum);
Err := SerReset(InRefNum, config);
Err := SerReset(OutRefNum, config);
end;
procedure closeserial;
begin
{ Err := FSClose(OutRefNum);}
{ Err := FSClose(InRefNum);}
err := closeDriver(InRefNum);
err := closeDriver(OutRefNum);
OutRefNum := 0;
InRefNum := 0;
end;
procedure getstr (id: integer; var s: str255);
var
tHndl: StringHandle;
begin
s := '';
tHndl := GetString(id);
s := concat(' ', tHndl^^, ' ');
end;
procedure getnumber (var numb: str255);
var
thndl: Handle;
l, offset: longInt;
begin
numb := '';
getstr(129, numb);
if (length(numb) = 2) then { 2 = blank. Why, I know not?!!! }
begin
tHndl := NewHandle(0);
l := GetScrap(tHndl, 'TEXT', offset);
if (offset > 0) then { it returned something useful. }
begin
GetIText(tHndl, numb); { cheat conversion }
end;
end;
end;
procedure sendstring (s: string);
var
i: integer;
c: char;
count: LongInt;
buffer: packed array[1..10] of char;
begin
count := 1;
for i := 1 to length(s) do
begin
buffer[1] := (s[i]);
Err := FSWrite(OutRefNum, count, @buffer);
end;
end;
procedure getstring (s: str255);
var
i: integer;
c: char;
count: longInt;
buffer, temp: ptr;
begin
Err := FSRead(inRefNum, count, buffer);
s := '';
for i := 0 to (count - 1) do
begin
temp := Ptr(Ord(Buffer) + i);
s[i] := Chr(temp^);
end;
end;
procedure dialnumber (numb: str255);
var
prefix: str255;
modemstr: str255;
begin
prefix := '';
getstr(128, prefix);
modemstr := concat(prefix, numb, ',;H0', chr(13));
sendstring(modemstr);
{ Any Hayes-compatible modem should be able to handle the semicolon H0 to hang up. }
end;
{ OBSOLETE procedure. 8/26/93 }
procedure sendhangup;
var
ticks: longInt;
begin
delay(65, ticks);
sendstring('+++');
delay(65, ticks);
sendstring(concat('ATH0', chr(13)));
end;
function ator (var s: str255): real;
{ This is really clumsy, but works just well enough for my needs. }
var
c: char;
f: real;
d, i: integer;
begin
d := 2; { before the number }
f := 0;
for i := 1 to length(s) do
begin
c := (s[i]);
if d = 2 then
begin
if ((c >= '0') and (c <= '9')) then
d := 1; { in the number }
end; { if before the number. }
if d = 1 then
begin
if ((c >= '0') and (c <= '9')) then
begin
f := (f * 10) + ord(c) - 48;
end
else if (c = '.') then
begin
d := -10;
end
else
begin
d := 0;
end; { what to do when left of decimal }
end { if left of decimal }
else if d < 0 then
begin
if ((c >= '0') and (c <= '9')) then
begin
f := f + ((ord(c) - 48) / (-d));
d := d * 10;
end
else
begin
d := 0;
end; { what to do when right of decimal }
end; { if in number}
{ else if d is 0, ignore the rest. }
end; { loop }
ator := f;
end;
{ This will wait for as many seconds as are present in str id 130 }
procedure waitasrequested;
var
ticks: longint;
s: str255;
f: real;
i, requested: longint;
begin
getstr(130, s);
f := ator(s); { make it a float/real }
requested := trunc(f * 12);
for i := 1 to requested do
begin
delay(5, ticks);
systemtask;
{ be somewhat nice, if only 12 times per second. }
end;
end;
{ Main }
begin
Init;
getnumber(numb);
if (length(numb) > 0) then
begin
openserial;
systemtask;
sendstring(concat('AT', chr(13)));
{ Wake up modem }
systemtask;
delay(60, waiter); { wait 1 seconds }
systemtask;
dialnumber(numb);
{ Attempt to wait for a response. }
{getstring(s);writeln('first response is');writeln(s);getstring(s);writeln('second response is');writeln(s);}
{writeln('hit return');readln;}
waitasrequested;
systemtask;
closeserial;
end
else
sysbeep(10); { No number found! }
end.